Ext.regModel('File', {
    idProperty: 'id',
    fields: [
        {name: 'id',       type: 'string'},
        {name: 'fileName', type: 'string'}
    ]
});

var param=window.location.href.split("=")[1];
Ext.setup({
    icon: 'icon.png',
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    glossOnIcon: false,
    onReady: function(){

        var store = new Ext.data.TreeStore({
            model: 'File',
            proxy: {
                type: 'ajax',
                url: 'dailyListCost_deailyListOfCost.action?param='+param,
                reader: {
                    type: 'tree',
                    root:'deailyListOfCost'
                }
            }
        });
        
        var nestedList = new Ext.NestedList({
            fullscreen: true,
            title: '报销费用详细信息',
            displayField: 'fileName',
            // add a / for folder nodes in title/back button
            getTitleTextTpl: function() {
                return '{' + this.displayField + '}<tpl if="leaf !== true"></tpl>';
            },
            // add a / for folder nodes in the list
            getItemTextTpl: function() {
                //return '{' + this.displayField + '}<tpl if="leaf !== true"></tpl>';
            	return '<div class="contact2"><strong>{'+ this.displayField +'}</strong></div>'  ;
            },
            forwardtojsp:function(num,reqparam){
            	switch(num){
            		case 001:
            			window.location.href='../../costmanagement/dailyCostSubmit/travalCostSubmit.jsp?reqparam='+reqparam;
            			break;
            		case 002:
            			window.location.href='../../costmanagement/dailyCostSubmit/partyCostDetail.jsp?reqparam='+reqparam;
            			break;
            		case 003:
            			window.location.href='../../costmanagement/dailyCostSubmit/otherCostDetail.jsp?reqparam='+reqparam;
            			break;
            		case 004:
            			window.location.href='../../costmanagement/dailyCostSubmit/lodgingCostDetail.jsp?reqparam='+reqparam;
            			break;
            		case 005:          			
            			window.location.href='../../costmanagement/dailyCostSubmit/purchaseCostSubmit.jsp?reqparam='+reqparam;
            			break;
            	}
            },
            store: store,
            toolbar: {
            	items: [{xtype: 'spacer'},{iconMask: true,iconCls: 'add',handler:function(){
            		 var temp = nestedList.getActiveItem();
            	        console.log(temp.recordNode.attributes.id);
            	        if('root'==temp.recordNode.attributes.id){
            	        	Ext.Msg.alert("请点击需要添加费用类型！");
            	        	return;
            	        }
            	        var reqparam=param+','+temp.recordNode.attributes.id+',';
            	        nestedList.forwardtojsp(parseInt(reqparam.split(',')[2]),reqparam);
                		
            	}}]
            }, 
        });
        
        nestedList.on('leafitemtap', function(subList, subIdx, el, e, detailCard) {
        	var ds = subList.getStore(),
                r  = ds.getAt(subIdx);
        	var temp = nestedList.getActiveItem();
        	var reqparam=param+','+temp.recordNode.attributes.id+','+r.data.id;
        	nestedList.forwardtojsp(parseInt(reqparam.split(',')[2]),reqparam);
        });
    }
});